/* the syscall.c file implements wrappers to Horizon syscalls */

#include <stdlib.h>
#include <syscall.h>

/* This is defined in the do_syscall.s file */
extern dword_t do_syscall(dword_t number,dword_t p1,dword_t p2,dword_t p3,dword_t p4,dword_t p5);


/* Function implementation */

size_t read(int fd,void *buf,size_t count)
{
  enum syscalls_t number = SYS_READ;

  return (size_t)do_syscall((dword_t)number,(dword_t)fd,(dword_t)buf,(dword_t)count,0,0);
}

size_t write(int fd,const void *buf,size_t count)
{
  enum syscalls_t number = SYS_WRITE;

  return (size_t)do_syscall((dword_t)number,(dword_t)fd,(dword_t)buf,(dword_t)count,0,0);
}

int brk(void *data_section_end)
{
  enum syscalls_t number = SYS_BRK;

  return (int)do_syscall((dword_t)number,(dword_t)data_section_end,0,0,0,0);
}

int submit(const char *name,int phase,int period,int exec_time,int deadline)
{
  enum syscalls_t number = SYS_SUBMIT;

  return (int)do_syscall((dword_t)number,(dword_t)name,(dword_t)phase,(dword_t)period,(dword_t)exec_time,(dword_t)deadline);
}

int yield(void)
{
  enum syscalls_t number = SYS_YIELD;

  return (int)do_syscall((dword_t)number,0,0,0,0,0);
}

dword_t time(void)
{
  enum syscalls_t number = SYS_TIME;

  return (dword_t)do_syscall((dword_t)number,0,0,0,0,0);
}

int quit(int code)
{
  enum syscalls_t number = SYS_QUIT;

  return (int)do_syscall((dword_t)number,(dword_t)code,0,0,0,0);
}

